// Verify that customer can register as a user successfully 

package com.selenium.webdriver;

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;

public class testRegistration {

	
	public static void main(String[] args) throws BiffException, IOException {
		
		//Open file and access to the sheet
		
		File inputFile = new File ("c:/test.xls");
		Workbook workbook = Workbook.getWorkbook(inputFile);
		Sheet sheet = workbook.getSheet(1);
		Cell cells;
		
		//Define string array that stores values of fields from the spreadsheet
		
		int sizeOfArray = sheet.getColumns();
		String[] textFields = new String[sizeOfArray];
		
		for(int i=0;i<sheet.getRows();i++)
			
		{	
			//Access to the website
			WebDriver driver = new FirefoxDriver();
			String baseUrl = "http://newtours.demoaut.com/";
			driver.get(baseUrl);
			//Initiate the login page
			loginPage loginpage = PageFactory.initElements(driver, loginPage.class);
			//Click register button 
			loginpage.registerAsMember();
			//Initiate registration page
			registrationPage registrationpage = PageFactory.initElements(driver, registrationPage.class);
			for (int j=0;j<sheet.getColumns();j++)
			{
			//Read and store a row data from the spreadsheet
			cells = sheet.getCell(j,i);
			textFields[j] = cells.getContents();
			}
			//Assign values to fields
			registrationpage.assignValueToTextFields(textFields);
			//Click submit button for registration
			registrationpage.clickRegisterButton();
			//Close the driver
			driver.close();
		}

	}

}
